from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from app.core.config import settings
from sqlalchemy.orm import sessionmaker, scoped_session

engine = create_engine(settings.SQLALCHEMY_DATABASE_URI, pool_pre_ping=True)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
session_factory = scoped_session(SessionLocal)
Base.metadata.create_all(bind=engine)

def get_db():
    db = session_factory()
    try:
        yield db
    finally:
        db.close()
        import pymysql